﻿Imports Conexiones.Class1
Imports System.Data.SqlClient

Public Class Form2

    Public var As New Conexiones.Class1

    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

    End Sub

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        var.adaptador.Fill(var.miDataset, "usuarios")

        DataGridView1.DataSource = var.miDataset
        DataGridView1.DataMember = "usuarios"

        Label3.Text = DataGridView1.RowCount - 1

        ComboBox1.DataSource = var.miDataset.Tables("usuarios")

        ComboBox1.DisplayMember = "nombre"

    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

        Dim cb As New SqlDataAdapter
        Dim comando = New SqlCommand(("select * from usuarios where nombre=@nombre"), var.conexion)

        Dim ds As New DataSet
        cb.SelectCommand = comando
        comando.Parameters.Add("@nombre", SqlDbType.VarChar, 15).Value = ComboBox1.Text

        ds.Clear()
        cb.Fill(ds, "usuarios")

        DataGridView1.DataSource = ds
        Label3.Text = DataGridView1.RowCount - 1



    End Sub


    Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged
        Dim comando = New SqlCommand(("select * from usuarios where nombre LIKE '%" & TextBox4.Text & "%'"), var.conexion)
        var.adaptador.SelectCommand = comando

        var.miDataset.Clear()
        var.adaptador.Fill(var.miDataset, "usuarios")

        DataGridView1.DataSource = var.miDataset

        Label3.Text = DataGridView1.RowCount - 1
    End Sub
End Class